﻿using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using Klear.Library.Services;


namespace Klear.Library.ViewModels;

public class MainWindowViewModel : ViewModelBase
{
    
    private readonly IDatabaseService _databaseService;
    private readonly IRootNavigationService _rootNavigationService;
    private readonly IMenuNavigationService _menuNavigationService;

    public MainWindowViewModel( IDatabaseService databaseService,
        IRootNavigationService rootNavigationService,
        IMenuNavigationService menuNavigationService
    ) {
        _databaseService = databaseService;
        _rootNavigationService = rootNavigationService;
        _menuNavigationService = menuNavigationService;
        
        OnInitializedCommand = new RelayCommand(OnInitialized);
    }
    
    private ViewModelBase _content;
    
    public ViewModelBase Content {
        get => _content;
        set => SetProperty(ref _content, value);
    }
    
    public ICommand OnInitializedCommand { get; }
    
    public void OnInitialized() {
        
        if (!_databaseService.IsDatabaseInitialized()) {
            _rootNavigationService.NavigateTo(RootNavigationConstant
                .InitializationView);
        } else {
            _rootNavigationService.NavigateTo(RootNavigationConstant.MainView);
            _menuNavigationService.NavigateTo(MenuNavigationConstant.IncomeExpensesView);
        }
    }
}